﻿@model IList<ProductAttributeCombinationModel.ProductAttributeModel>
@if (Model.Count > 0)
{
    <div class="form-group">
        @foreach (var attribute in Model)
        {
            var controlId = $"attributes[{attribute.Id}]";
            var textPrompt = !string.IsNullOrEmpty(attribute.TextPrompt) ? attribute.TextPrompt : attribute.Name;
            <div class="form-group">
                <div class="col-md-3 col-sm-3">
                    @if (attribute.IsRequired)
                    {
                        <span class="required">*</span>
                    }
                    <label class="control-label">@textPrompt</label>
                </div>
                <div class="col-md-9 col-sm-9">
                    @switch (attribute.AttributeControlType)
                    {
                        case AttributeControlType.DropdownList:
                        {
                            <select name="@(controlId)" id="@(controlId)" class="form-control">
                                @if (!attribute.IsRequired)
                                {
                                    <option value="">---</option>
                                }
                                @foreach (var attributeValue in attribute.Values)
                                {
                                    <option selected="@attributeValue.IsPreSelected" value="@attributeValue.Id">
                                        @attributeValue.Name
                                    </option>
                                }
                            </select>
                        }
                            break;
                        case AttributeControlType.RadioList:
                        case AttributeControlType.ColorSquares:
                        case AttributeControlType.ImageSquares:
                        {
                            foreach (var attributeValue in attribute.Values)
                            {
                                <div>
                                    <label>
                                        <input id="@(controlId)" type="radio" name="@(controlId)" value="@attributeValue.Id" checked="@attributeValue.IsPreSelected"/>
                                        @attributeValue.Name
                                    </label>
                                </div>
                            }
                        }
                            break;
                        case AttributeControlType.Checkboxes:
                        case AttributeControlType.ReadonlyCheckboxes:
                        {
                            foreach (var attributeValue in attribute.Values)
                            {
                                <div>
                                    <label>
                                        <input id="@(controlId)" type="checkbox" name="@(controlId)" value="@attributeValue.Id" checked="@attributeValue.IsPreSelected" @(attribute.AttributeControlType == AttributeControlType.ReadonlyCheckboxes ? Html.Raw(" disabled=\"disabled\"") : null)/>
                                        @attributeValue.Name
                                    </label>
                                </div>
                            }
                        }
                            break;
                        case AttributeControlType.TextBox:
                        {
                            <input name="@(controlId)" type="text" id="@(controlId)" class="form-control"/>
                        }
                            break;
                        case AttributeControlType.MultilineTextbox:
                        {
                            <textarea cols="20" id="@(controlId)" name="@(controlId)" rows="2" class="form-control"></textarea>
                        }
                            break;
                        case AttributeControlType.Datepicker:
                        {
                            <date-picker-dropdown control-day="@(controlId + "_day")"
                                                  control-month="@(controlId + "_month")"
                                                  control-year="@(controlId + "_year")"
                                                  begin-year="@(DateTime.Now.Year)"
                                                  end-year="@(DateTime.Now.Year + 1)"
                                                  PartialViewName="Partials/DateDropDowns"
                                                  class="col-12 input-group"/>
                        }
                            break;
                        case AttributeControlType.FileUpload:
                        {
                            <input type="file" id="@(controlId)" name="@(controlId)" class="form-control"/>
                        }
                            break;
                    }
                </div>
            </div>
        }
    </div>
}